//
//  ContextMenuBoot.swift
//  SwiftUIWidgetDemo
//
//  Created by alanzhangg on 2023/7/16.
//

import SwiftUI

struct ContextMenuBoot: View {
    
    @State var backgroundColor: Color = .blue
    
    var body: some View {
        VStack(alignment: .leading){
            Image(systemName: "house.fill")
                .font(.title)
            Text("swiftful thinking")
                .font(.headline)
            Text("how to use contextMenu")
                .font(.subheadline)
        }
        .foregroundStyle(.white)
        .padding(30)
        .background(
            RoundedRectangle(cornerRadius: 30)
                .fill(backgroundColor)
        )
        .contextMenu(menuItems: {
            Button(action: {
                backgroundColor = .yellow
            }, label: {
                Label(
                    title: { Text("Button 1") },
                    icon: { Image(systemName: "flame.fill") }
                )
            })
            
            Button(action: {
                backgroundColor = .purple
            }, label: {
                Text("Button 2")
            })
            
            Button(action: {
                backgroundColor = .blue
            }, label: {
                HStack{
                    Text("Button 3")
                    Image(systemName: "heart.fill")
                }
            })
            
        })
        
    }
}

#Preview {
    ContextMenuBoot()
}
